package com.api.sw.duban.util;

import com.alibaba.fastjson.JSONObject;
import com.api.sw.duban.baseinter.Execute;
import com.api.sw.duban.impl.ExecuteImpl;
import weaver.general.Util;

import java.util.concurrent.ConcurrentHashMap;

public class CacheUtil {
    private static volatile CacheUtil cacheUtil = null;
    private static final ConcurrentHashMap<String, Execute> rightCurrentUserMap = new ConcurrentHashMap<String, Execute>();

    private CacheUtil() {
    }

    public static CacheUtil getInstance() {
        Class var0 = CacheUtil.class;
        synchronized(CacheUtil.class) {
            if (cacheUtil == null) {
                cacheUtil = new CacheUtil();
            }
        }

        return cacheUtil;
    }
    //获取以及设置
    public synchronized Execute getExecute(String pid, String mothed, JSONObject param){
          if(pid==null||"".equals(Util.null2String(pid).trim())){
              return null;
          }
          Execute Execute=rightCurrentUserMap.get(pid);
          if(Execute==null){
              Execute =new ExecuteImpl(pid,mothed,param);
              rightCurrentUserMap.put(pid,Execute);
          }
          return Execute;
    }
    //移除
    public synchronized void removeExecute(String pid){
        if(pid==null||"".equals(Util.null2String(pid).trim())){
            return ;
        }
        if(rightCurrentUserMap.containsKey(pid)){
            rightCurrentUserMap.remove(pid);
        }
    }
}
